package com.example.designPatten.observer.ObserverJavaAPI;

import java.util.Observable;
import java.util.Observer;

import com.example.designPatten.observer.ObserverJavaAPI.inter.DisplayElement;


/**
* @Title:   []
* @Description: 
* @Date : 2016年4月20日下午4:56:37
* @Company: SI-TECH
* @author : LIJXD
* @version : 1.0
* @modify history
*  <p>修改日期    修改人   修改目的<p> 	
*/
public class CurrendConditionDiaplay implements Observer, DisplayElement {


	private float temperature;
	private float humidity;
	private Observable observable;
	
	
	
	public CurrendConditionDiaplay(Observable observable) {
		this.observable = observable;
		observable.addObserver(this);
	}


	@Override
	public void display() {
		System.out.println("Current Condition  : temperature="+temperature+" , humidity="+humidity);
	}


	/* (non-Javadoc)
	 * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
	 */
	@Override
	public void update(Observable o, Object arg) {
		// TODO Auto-generated method stub
		if(o instanceof WeatherData){
			WeatherData weatherData = (WeatherData) o;
			this.temperature = weatherData.getTemperature();
			this.humidity = weatherData.getHumidity();
			display();
		}
	}

}
